project(nanomsg)

ExternalProject_Add(build-${PROJECT_NAME}
    URL ${PROJECT_SOURCE_DIR}/src/nanomsg-1.1.5.tar.gz
    CMAKE_COMMAND cmake -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR}/build-${PROJECT_NAME}-prefix -DNN_TESTS=OFF -DNN_ENABLE_DOC=OFF
    BUILD_COMMAND make
    INSTALL_COMMAND make install
    COMMAND rm -rf ${PROJECT_BINARY_DIR}/build-${PROJECT_NAME}-prefix/lib/cmake
    COMMAND rm -rf ${PROJECT_BINARY_DIR}/build-${PROJECT_NAME}-prefix/lib/pkgconfig)

# set search path
set(NANOMSG_HEADER_DIR "${PROJECT_BINARY_DIR}/build-${PROJECT_NAME}-prefix/include"
    CACHE PATH INTERNAL FORCE)
set(NANOMSG_LINK_DIR "${PROJECT_BINARY_DIR}/build-${PROJECT_NAME}-prefix/lib"
    CACHE PATH INTERNAL FORCE)

# install lib.so
install(DIRECTORY "${NANOMSG_LINK_DIR}/" DESTINATION ${CMAKE_INSTALL_LIBDIR}
    FILES_MATCHING PATTERN "libnanomsg.so*")